import pymysql
from pyecharts import options
from pyecharts.charts import Pie

#连接数据库
db=pymysql.connect(
    host="localhost",
    user="root",
    password="12345",
    database="crawlerdemo",
    charset="utf8"
)

cursor=db.cursor()

#查岗位数量最多的城市
sql="select job_place,count(job_id) from job group by job_place order by count(job_id) desc limit 5"

try:
    cursor.execute(sql)

except Exception as e:
    print(e)
    #print("查询出错了")

res = cursor.fetchall()
pie=Pie()
#[（"类型1"，30），（"类型1"，30）......]
pie.add("单位/个",res)
pie.set_global_opts(title_opts=options.TitleOpts(title="五个城市的岗位数"))
pie.render("piera.html")
cursor.close()
db.close()